package Bacterias;

import android.util.Log;

import com.game.ThauanFramework.TimeManager;

public class HelmetRunnable implements Runnable {
	
	private final String TAG = "Helmet Runnable"; 
	private final int interval = 10;
	public boolean isAlive = true;
	public void setAlive(boolean isAlive){
		this.isAlive = isAlive;
	}
	
	private HelmetBacteria helmetBacteria;
	
	private float timeToRemoveHelmet = 0.5f;
	private float timeOnStartToRemoveHelmet = 0.5f;
	
	private boolean toRemoveHelmetState = false;
	
	private float cronometer = 0;
	
	public HelmetRunnable(HelmetBacteria helmetBacteria ){
		this.helmetBacteria = helmetBacteria;
		
		Thread thread = new Thread(this);
		thread.start();
	}

	@Override
	public void run() {
		while(isAlive){
			
			try {
				Thread.sleep(interval);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			cronometer += TimeManager.getInstance().getDeltaTime();
			Log.i(TAG, " cronometer: " + String.valueOf(cronometer));
			if(!toRemoveHelmetState){
			
			if(cronometer >= timeOnStartToRemoveHelmet )
			{
				// go to state of " can remove helmet"
				Log.i(TAG, "--  Runnable : To Remote Helmet  --");
				this.toRemoveHelmetState = true;
				helmetBacteria.ChangeForToRemoveHelmet(true);
				cronometer = 0;
			}
			
			}else
			{
				if(cronometer >= timeToRemoveHelmet )
				{
					// return to the state of " can't remove helmet "
					Log.i(TAG, "--  Runnable : Stop To Remove Helmet  --");
					helmetBacteria.ChangeForToRemoveHelmet(false);
					setAlive(false);
				}
			}
		}
		
	}
}
